package com.ls.demo.http.config;

import com.ls.demo.http.handler.HttpRequestHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author liShan
 * @date 2019/8/28 16:13
 */
@Component
public class HttpServerChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Resource
    private HttpRequestHandler httpRequestHandler;

    @Override
    protected void initChannel(SocketChannel ch){
        ch.pipeline()
                .addLast("httpRequestDecoder", new HttpRequestDecoder())
                .addLast("httpObjectAggregator", new HttpObjectAggregator(1024 * 1024 * 1024))
                .addLast("httpResponseEncoder", new HttpResponseEncoder())
                .addLast("handler", httpRequestHandler);
    }

}
